use warnings;
use Inline C;
use Test::More 'no_plan';


# test gen_frm_ctrl_t
is(gen_frm_ctrl_t(1, 0, 0, 1, 1, 2, 1, 2), 39009, 'generate frmame control field.');
is(gen_frm_ctrl_t(0, 0, 0, 1, 1, 2, 1, 2), 39008, 'generate frmame control field.');
is(gen_frm_ctrl_t(2, 0, 0, 1, 1, 2, 1, 2), 39010, 'generate frmame control field.');
is(gen_frm_ctrl_t(3, 0, 0, 1, 1, 2, 1, 2), 39011, 'generate frmame control field.');

is(gen_frm_ctrl_t(1, 1, 0, 1, 1, 2, 1, 2), 39017, 'generate frmame control field.');
is(gen_frm_ctrl_t(0, 1, 0, 1, 1, 2, 1, 2), 39016, 'generate frmame control field.');
is(gen_frm_ctrl_t(2, 1, 0, 1, 1, 2, 1, 2), 39018, 'generate frmame control field.');
is(gen_frm_ctrl_t(3, 1, 0, 1, 1, 2, 1, 2), 39019, 'generate frmame control field.');

is(gen_frm_ctrl_t(1, 0, 1, 1, 1, 2, 1, 2), 39025, 'generate frmame control field.');
is(gen_frm_ctrl_t(0, 0, 1, 1, 1, 2, 1, 2), 39024, 'generate frmame control field.');
is(gen_frm_ctrl_t(2, 0, 1, 1, 1, 2, 1, 2), 39026, 'generate frmame control field.');
is(gen_frm_ctrl_t(3, 0, 1, 1, 1, 2, 1, 2), 39027, 'generate frmame control field.');

is(gen_frm_ctrl_t(1, 0, 0, 0, 1, 2, 1, 2), 38977, 'generate frmame control field.');
is(gen_frm_ctrl_t(0, 0, 0, 0, 1, 2, 1, 2), 38976, 'generate frmame control field.');
is(gen_frm_ctrl_t(2, 0, 0, 0, 1, 2, 1, 2), 38978, 'generate frmame control field.');
is(gen_frm_ctrl_t(3, 0, 0, 0, 1, 2, 1, 2), 38979, 'generate frmame control field.');

is(gen_frm_ctrl_t(1, 0, 0, 1, 0, 2, 1, 2), 38945, 'generate frmame control field.');
is(gen_frm_ctrl_t(0, 0, 0, 1, 0, 2, 1, 2), 38944, 'generate frmame control field.');
is(gen_frm_ctrl_t(2, 0, 0, 1, 0, 2, 1, 2), 38946, 'generate frmame control field.');
is(gen_frm_ctrl_t(3, 0, 0, 1, 0, 2, 1, 2), 38947, 'generate frmame control field.');

is(gen_frm_ctrl_t(1, 0, 0, 1, 1, 0, 1, 2), 36961, 'generate frmame control field.');
is(gen_frm_ctrl_t(0, 0, 0, 1, 1, 0, 1, 2), 36960, 'generate frmame control field.');
is(gen_frm_ctrl_t(2, 0, 0, 1, 1, 0, 1, 2), 36962, 'generate frmame control field.');
is(gen_frm_ctrl_t(3, 0, 0, 1, 1, 0, 1, 2), 36963, 'generate frmame control field.');

is(gen_frm_ctrl_t(1, 0, 0, 1, 1, 3, 1, 2), 40033, 'generate frmame control field.');
is(gen_frm_ctrl_t(0, 0, 0, 1, 1, 3, 1, 2), 40032, 'generate frmame control field.');
is(gen_frm_ctrl_t(2, 0, 0, 1, 1, 3, 1, 2), 40034, 'generate frmame control field.');
is(gen_frm_ctrl_t(3, 0, 0, 1, 1, 3, 1, 2), 40035, 'generate frmame control field.');

is(gen_frm_ctrl_t(1, 0, 0, 1, 1, 2, 0, 2), 34913, 'generate frmame control field.');
is(gen_frm_ctrl_t(0, 0, 0, 1, 1, 2, 0, 2), 34912, 'generate frmame control field.');
is(gen_frm_ctrl_t(2, 0, 0, 1, 1, 2, 0, 2), 34914, 'generate frmame control field.');
is(gen_frm_ctrl_t(3, 0, 0, 1, 1, 2, 0, 2), 34915, 'generate frmame control field.');

is(gen_frm_ctrl_t(1, 0, 0, 1, 1, 2, 1, 0), 6241, 'generate frmame control field.');
is(gen_frm_ctrl_t(0, 0, 0, 1, 1, 2, 1, 0), 6240, 'generate frmame control field.');
is(gen_frm_ctrl_t(2, 0, 0, 1, 1, 2, 1, 0), 6242, 'generate frmame control field.');
is(gen_frm_ctrl_t(3, 0, 0, 1, 1, 2, 1, 0), 6243, 'generate frmame control field.');

is(gen_frm_ctrl_t(1, 0, 0, 1, 1, 2, 1, 3), 55393, 'generate frmame control field.');
is(gen_frm_ctrl_t(0, 0, 0, 1, 1, 2, 1, 3), 55392, 'generate frmame control field.');
is(gen_frm_ctrl_t(2, 0, 0, 1, 1, 2, 1, 3), 55394, 'generate frmame control field.');
is(gen_frm_ctrl_t(3, 0, 0, 1, 1, 2, 1, 3), 55395, 'generate frmame control field.');

# test calc_hdr_len_t
is(calc_hdr_len_t(1, 0, 0, 1, 0, 3, 0, 3), 23, 'the length of the hdr should be 23.');
is(calc_hdr_len_t(1, 0, 0, 1, 1, 3, 0, 3), 21, 'the length of the hdr should be 21.');
is(calc_hdr_len_t(1, 0, 0, 1, 1, 2, 0, 3), 15, 'the length of the hdr should be 15.');
is(calc_hdr_len_t(1, 0, 0, 1, 1, 3, 0, 2), 15, 'the length of the hdr should be 15.');
is(calc_hdr_len_t(1, 0, 0, 1, 1, 2, 0, 2), 9, 'the length of the hdr should be 9.');
is(calc_hdr_len_t(1, 0, 0, 1, 1, 0, 0, 2), 5, 'the length of the hdr should be 5.');
is(calc_hdr_len_t(1, 0, 0, 1, 1, 0, 0, 0), 3, 'the length of the hdr should be 3.');
is(calc_hdr_len_t(1, 0, 0, 1, 1, 0, 1, 0), 3, 'the length of the hdr should be 3, but pan_id_comp should be 1.');


__END__
__C__

#include <string.h>
#include "../../../../mac/mac_gen.h"
#include "../../../../mac/mac_gen.c"
#include "mac_gen_test.c"
#include "../../../../mac/mac_parse.h"
#include "../../../../mac/mac_parse.c"

int gen_frm_ctrl_t(unsigned char frm_type, unsigned char en_sec, unsigned char frm_pend,
        unsigned char ack, unsigned char pan_id_comp, unsigned char dest_addr_m, unsigned char frm_ver, 
        unsigned char src_addr_m)
{
    return mac_gen_frm_ctrl_test(frm_type, en_sec, frm_pend, ack, pan_id_comp,
                         dest_addr_m, frm_ver, src_addr_m);
}

int calc_hdr_len_t(unsigned char frm_type, unsigned char en_sec, unsigned char frm_pend,
        unsigned char ack, unsigned char pan_id_comp, unsigned char dest_addr_m, unsigned char frm_ver, 
        unsigned char src_addr_m)
{
    return calc_hdr_len_test(frm_type, en_sec, frm_pend, ack, pan_id_comp,
                         dest_addr_m, frm_ver, src_addr_m);
}

/*
int ack_cmp_t(int dsn)
{
    buf_t buf;
    mac_hdr_t hdr;
    mac_frm_ctrl_t *ctrl = &hdr.ctrl;

    buf.ptr = &buf.array[127];
    buf.length = 0;

    mac_gen_ack(&buf, dsn);
    mac_parse_hdr(&buf, &hdr);

    if (hdr.dsn == dsn &&
        ctrl->frm_type     == FRM_TYPE_ACK &&
        ctrl->en_sec       == 0            && 
        ctrl->ack          == 1            &&
        ctrl->frm_pend     == 0            &&
        ctrl->pan_id_comp  == 0            &&
        ctrl->dest_addr_m  == 0            &&
        ctrl->frm_ver      == v_2006       &&
        ctrl->src_addr_m   == 0) {

        return 0;
    } else {
        return -1;
    }
}
*/



